package com.example.webbasic.filter;

import java.io.IOException;
import java.util.function.Consumer;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.springframework.core.annotation.Order;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;

/**
 * MyFilter4
 * 检查 过滤器 顺序 
 * @author ben
 * @date 2021-11-06 17:04:08 CST
 */
@Component
public class MyFilter4 implements Filter {

	private static Consumer<Object> cs = System.out::println;
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		cs.accept("MyFilter4 过滤器初始化：" + MyFilter4.class);
	}
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		// 可以做什么呢？
		cs.accept("MyFilter4 req=" + req + ", param.key=" + req.getParameter("key"));
		cs.accept("MyFilter4 attr.key=" + req.getAttribute("key"));
		cs.accept("MyFilter4 执行过滤操作...scheme=" + req.getScheme());
		chain.doFilter(req, resp);
	}
	
	@Override
	public void destroy() {
		cs.accept("MyFilter4 过滤器销毁：" + MyFilter4.class);
	}

}
